<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    const str = '黑马程序员'
    // 编码
    console.log( encodeURI(str))  //%E9%BB%91%E9%A9%AC%E7%A8%8B%E5%BA%8F%E5%91%98
    // 解码
    console.log(decodeURI('%E9%BB%91')) //黑 

    console.log(encodeURI('红&黑'))  //%E7%BA%A2&%E9%BB%91  特殊字符&不会编码
    console.log(encodeURIComponent('红&黑')) //%E7%BA%A2%26%E9%BB%91 特殊字符&会被编码

    console.log(decodeURIComponent('%E7%BA%A2%26%E9%BB%91')) // 红&黑  特殊字符会被解码
      
  </script>
</body>

</html>